<h:panelGroup layout="block"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxr="http://nuxeo.org/nxweb/resources"
  styleClass="nx-elements">

  <h:outputScript src="/bower_components/webcomponentsjs/webcomponents-lite.js" target="#{pageJsTarget}" />
  <h:outputScript src="/bower_components/moment/min/moment-with-locales.min.js" target="#{pageJsTarget}" />
  <h:outputScript target="#{pageJsTarget}">
    var lang = navigator.language || navigator.browserLanguage;
    moment.locale(lang);
  </h:outputScript>

  <nxr:import src="/permissions/components/elements.vulcanized.html" target="#{pageJsTarget}" />

  <h:outputScript target="#{pageJsTarget}">
    var nuxeo = (function (nuxeo) {
      nuxeo.elements = (function(elements) {
        elements.labels = {
          'label.permissions.locallyDefined': "#{messages['label.permissions.locallyDefined']}",
          'label.permissions.userGroup': "#{messages['label.permissions.userGroup']}",
          'label.permissions.right': "#{messages['label.permissions.right']}",
          'label.permissions.timeFrame': "#{messages['label.permissions.timeFrame']}",
          'label.permissions.grantedBy': "#{messages['label.permissions.grantedBy']}",
          'label.permissions.actions': "#{messages['label.permissions.actions']}",
          'label.permissions.noLocalPermissions': "#{messages['label.permissions.noLocalPermission']}",
          'label.permissions.inherited': "#{messages['label.permissions.inherited']}",
          'label.permissions.block': "#{messages['label.permissions.block']}",
          'label.permissions.unblock': "#{messages['label.permissions.unblock']}",
          'label.permissions.deleteConfirmation': "#{messages['label.permissions.deleteConfirmation']}",
          'label.permissions.newPermission': "#{messages['label.permissions.newPermission']}",
          'label.permissions.addPermission': "#{messages['label.permissions.addPermission']}",
          'label.permissions.updatePermission': "#{messages['label.permissions.updatePermission']}",
          'label.permissions.from': "#{messages['label.permissions.from']}",
          'label.permissions.to': "#{messages['label.permissions.to']}",
          'label.permissions.until': "#{messages['label.permissions.until']}",
          'label.permissions.untilMiddle': "#{messages['label.permissions.untilMiddle']}",
          'label.permissions.since': "#{messages['label.permissions.since']}",
          'label.permissions.notify': "#{messages['label.permissions.notify']}",
          'label.permissions.notifyPlaceholder': "#{messages['label.permissions.notifyPlaceholder']}",
          'label.permissions.cancel': "#{messages['label.permissions.cancel']}",
          'label.permissions.createAndAdd': "#{messages['label.permissions.createAndAdd']}",
          'label.permissions.create': "#{messages['label.permissions.create']}",
          'label.permissions.update': "#{messages['label.permissions.update']}",
          'label.permissions.noInheritedText': "#{messages['label.permissions.noInheritedText']}",
          'label.permissions.blocked': "#{messages['label.permissions.blocked']}",
          'label.permissions.permanent': "#{messages['label.permissions.permanent']}",
          'label.permissions.dateBased': "#{messages['label.permissions.dateBased']}",
          'label.permissions.blockDescription': "#{messages['label.permissions.blockDescription']}",
          'label.permissions.permissionCreated': "#{messages['label.permissions.permissionCreated']}",
          'label.permissions.permissionUpdated': "#{messages['label.permissions.permissionUpdated']}",
          'label.permissions.permissionDeleted': "#{messages['label.permissions.permissionDeleted']}",
          'label.permissions.permissionNotificationSent': "#{messages['label.permissions.permissionNotificationSent']}",
          'label.permissions.shareWithExternalUser': "#{messages['label.permissions.shareWithExternalUser']}",
          'label.permissions.external': "#{messages['label.permissions.external']}",
          'label.permissions.externalDescription': "#{messages['label.permissions.externalDescription']}",
          'label.permissions.noExternalPermission': "#{messages['label.permissions.noExternalPermission']}",
          'command.delete': "#{messages['command.delete']}",
          <c:forEach var="permissionToLabel" items="#{securityActions.permissionsToLabels.entrySet()}" varStatus="status">
          '#{permissionToLabel.key}': "#{messages[permissionToLabel.value]}"<c:if test="#{not status.last}">,</c:if>
          </c:forEach>
        };
        return elements;
      })(nuxeo.elements || {});
      return nuxeo;
    })(nuxeo || {});
  </h:outputScript>

  <nxu:set var="testerName" value="#{frameworkPropertyActions.getProperty('org.nuxeo.ecm.tester.name')}">
    <c:if test="#{testerName == 'Nuxeo-Selenium-Tester'}">
      <h:outputScript target="#{pageJsTarget}">
        window.onerror = function(msg){
          jQuery("body").attr("JSError", msg);
          jQuery.get("restAPI/systemLog?token=dolog&amp;level=WARN&amp;message=----- JS error: " + msg);
        }
      </h:outputScript>
    </c:if>
  </nxu:set>

  <template is="dom-bind">

    <nuxeo-connection id="nx_connection" url="#{baseURL}" repository-name="#{currentDocument.repositoryName}"></nuxeo-connection>
    <nuxeo-document-permissions doc-id="#{currentDocument.id}"></nuxeo-document-permissions>

  </template>

</h:panelGroup>
